Gemini API | Google AI for Developers
Gemini API Developer Docs and API Reference
On this page
Get started with the Gemini API
bookmark_border Stay organized with collections Save and categorize content based on your preferences.
The Gemini API and Google AI Studio help you start working with Google’s latest models and turn your ideas into applications that scale.
<span>import</span> <span>google.generativeai</span> <span>as</span> <span>genai</span>
<span>genai</span><span>.</span><span>configure</span><span>(</span><span>api_key</span><span>=</span><span>"<devsite-var rendered="" translate="no" is-upgraded="" scope="YOUR_API_KEY" tabindex="0"><span><var spellcheck="false" is-upgraded="" data-title="Edit YOUR_API_KEY" aria-label="Edit YOUR_API_KEY">YOUR_API_KEY</var></span></devsite-var>"</span><span>)</span>
<span>model</span> <span>=</span> <span>genai</span><span>.</span><span>GenerativeModel</span><span>(</span><span>"gemini-1.5-flash"</span><span>)</span>
<span>response</span> <span>=</span> <span>model</span><span>.</span><span>generate_content</span><span>(</span><span>"Explain how AI works"</span><span>)</span>
<span>print</span><span>(</span><span>response</span><span>.</span><span>text</span><span>)</span>
1.5 Flash
Our most balanced multimodal model with great performance for most tasks
1.5 Flash-8B
Our fastest and most cost-efficient multimodal model with great performance for high-frequency tasks
1.5 Pro
Our best performing multimodal model with features for a wide variety of reasoning tasks
Explore the API
Explore long context
Input millions of tokens to Gemini models and derive understanding from unstructured images, videos, and documents.
Solve tasks with fine-tuning
Modify the behavior of Gemini models to adapt to specific tasks, recognize data, and solve problems. Tune models with your own data to make production deployments more robust and reliable.
Generate structured outputs
Constrain Gemini to respond with JSON, a structured data format suitable for automated processing.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-11-14 UTC.